package de.mahosoftware.gwt.games.durak.util;

import java.util.List;

import de.mahosoftware.gwt.games.durak.client.module.Card;
import de.mahosoftware.gwt.games.durak.client.module.Card.Color;
import de.mahosoftware.gwt.games.durak.client.module.Player;

public class CardDealer extends Player {

	public CardDealer() {
		super("Dealer");
		init();
		// testCase();
	}

	private void testCase() {
		for (int i = 0; i < 8; i++) {
			randomCard();
		}
	}

	private void init() {
		Card c;
		for (int i = 7; i <= 14; i++) {
			for (int j = 0; j < 4; j++) {
				c = new Card(i, Color.values()[j]);
				getCard(c);
			}
		}
	}

	public Card randomCard() {
		int index = (int) (Math.random() * hand.size());
		return giveCard(index);
	}

	public boolean giveCards(int maxCards, List<Player> players) {
		for (int i = 0; i < maxCards; i++) {
			for (Player p : players) {
				if (p.getHand().size() <= maxCards) {
					p.getCard(randomCard());
				}
			}
		}
		return true;
	}

}
